//
//  WZDetailTaskController.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/6/21.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "WZDetailTaskController.h"
#import "WZDetailTask.h"
#import "CFolderMgr.h"
#import "CContactMgr.h"
#import "CContactModel.h"
#import "CAccountModel.h"
#import "WZTaskLogController.h"

@interface WZDetailTaskController ()

@property (weak, nonatomic) IBOutlet UILabel *taskName;
@property (weak, nonatomic) IBOutlet UILabel *desc;
@property (weak, nonatomic) IBOutlet UILabel *beginTime;
@property (weak, nonatomic) IBOutlet UILabel *endTime;
@property (weak, nonatomic) IBOutlet UILabel *projectName;
@property (weak, nonatomic) IBOutlet UILabel *statusName;
@property (weak, nonatomic) IBOutlet UILabel *progress;
@property (weak, nonatomic) IBOutlet UILabel *exturoName;
@property (weak, nonatomic) IBOutlet UILabel *assignerName;
@property (weak, nonatomic) IBOutlet UITextView *refuseReason;

@property (nonatomic, strong) CContactModel *curAccount;
@property (nonatomic, strong) CAccountModel *acc;

@property (nonatomic, strong) WZDetailTask *detailTask;

@end

@implementation WZDetailTaskController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self setupTableView];
    
    [self getTaskDetailInfor];
}


- (void)setupTableView {
    
    self.tableView.backgroundColor = WZRGBColor(245, 246, 249);
    self.title = @"任务详情";
    self.tableView.tableFooterView = [[UIView alloc] init];
    
//    CAccountModel *acc = [[CFolderMgr shareInstance].accMgr getRecentlyLoginAccount];
//    self.acc = acc;
//    self.curAccount = [[[CContactMgr alloc] init] loadContactWithUserCode:acc.userName];
    
//    self.tableView.scrollEnabled = NO;
}


/**任务详细信息*/
- (void)getTaskDetailInfor {
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"name"] = self.oaUserName;
    params[@"pwd"] = self.oaPwd;
    params[@"taskId"] = self.taskId;
    
    [NetWorkShare getTaskDetailInforWithParams:params SuccessHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject) {
            
            if ([[responseObject objectForKey:@"success"] boolValue]) {
                
                self.detailTask = [WZDetailTask objectWithKeyValues:responseObject[@"detail"]];
                
                [self loadData];
                
                [self.tableView reloadData];
                
                WZLog(@"%@", responseObject);
            } else {
                [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
            }
        } else {
            
            [MBProgressHUD showError:UNKNOWNERROR];
        }
    } FailureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD showError:NETWORKNERROR];
        WZLog(@"error = %@", error);
    }];
    
}

- (void)loadData {
    
    self.taskName.text = self.detailTask.taskName;
    self.desc.text = self.detailTask.remark;
    self.beginTime.text = self.detailTask.planExecBeginDate;
    self.endTime.text = self.detailTask.planExecEndDate;
    self.projectName.text = self.detailTask.projectName;
    self.exturoName.text = self.detailTask.executorName;
    self.assignerName.text = self.detailTask.assignerName;
    self.statusName.text = self.detailTask.statusName;
    self.refuseReason.text = self.detailTask.refuseReason;
    self.progress.text = [NSString stringWithFormat:@"%@%%", self.detailTask.progress];
    
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
    if (0 == section) {
        
        return nil;
        
    } else {
        
        return @"拒绝原因";
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (0 == section) {
        
        return 0.01;
    } else {
        
        return 30;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (6 == indexPath.row) {
        
        WZTaskLogController *logVc = [[WZTaskLogController alloc] init];
        logVc.taskId = self.taskId;
        logVc.oaUserName = self.oaUserName;
        logVc.oaPwd = self.oaPwd;
        [self.navigationController pushViewController:logVc animated:YES];
    }
}

@end
